<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        [v-cloak]{
            display: none;/*隐藏元素*/
        }
    </style>
</head>
<body>
<table v-cloak border="1">
    <caption>员工列表</caption>
    <tr>
        <th>id</th>
        <th>名字</th>
        <th>工资</th>
        <th>工作</th>
        <th>操作</th>
    </tr>
    <tr v-for="emp in arr">
        <td>{{emp.id}}</td>
        <td><a :href="'/update.html?id='+emp.id">{{emp.name}}</a></td>
        <td>{{emp.sal}}</td>
        <td>{{emp.job}}</td>
        <!--:href 属性绑定-->
        <td><a href="#" @click="del(emp.id)">删除</a></td>
    </tr>
</table>
<!--引入vue-->
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<!--引入axios框架-->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
    let vm = new Vue({
        el:"table",
        data:{
            arr:[]
        },
        created:function () {
            //发出异步请求
            axios.get("/select").then(function (response) {
                vm.arr = response.data;
            })
        },
        methods:{
            del:function (id) {
                if(confirm("您确认删除吗?")){
                    //发出异步请求
                    axios.get("/delete?id="+id).then(function () {
                        alert("删除成功!");
                        location.reload();//刷新
                    })
                }
            }

        }
    })
</script>
</body>
</html>